Data Visualization Toolkit: Using JavaScript, Rails, and Postgres to Present Data and Geospatial Information (Addison-Wesley Professional Ruby Series) by Barrett Clark

Data Visualization Toolkit: Using JavaScript, Rails, and Postgres to Present Data and Geospatial Information (Addison-Wesley Professional Ruby Series) by Barrett Clark

Author:Barrett Clark [Clark, Barrett]
Language: eng
Format: azw3
Publisher: Pearson Education
Published: 2016-08-04T04:00:00+00:00


Finalizing the Matrix

Now that we have our matrix generator we need to put it to work. Go back to the Departure class and have it extend DepartureMatrix. Now DepartureMatrix#airports_matrix! becomes a class method in Departure. We just need to call it, like so:

Click here to view code image

def self.departure_matrix

sql = <<-SQL.strip_heredoc

SELECT origin, dest, count(*)

FROM departures

WHERE unique_carrier = 'AA'

GROUP BY 1, 2

ORDER BY 1, 2

SQL

counts = connection.execute(sql)

airports_matrix!(:counts => counts)

end

You can run this from the console to see what your matrix looks like. It should be a large array of arrays.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.